package com.shopping.mall.core.module.user.service.impl;

import com.alibaba.excel.EasyExcel;
import com.shopping.mall.core.module.user.SubjectExcelListener;
import com.shopping.mall.core.module.user.entity.UserExcelVo;
import com.shopping.mall.core.module.user.mapper.UserMapper;
import com.shopping.mall.core.module.user.service.UserExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author ZZY
 * @Date 2021/12/8
 */
@Service
public class UserExcelServiceImpl implements UserExcelService {
    @Autowired
    private UserMapper userMapper;
    @Override
    @Async
    public void saveSubject(MultipartFile file) {
        try {
            //文件输入流
            InputStream in = file.getInputStream();
            EasyExcel.read(in, UserExcelVo.class, new SubjectExcelListener(userMapper)).sheet().doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}